package com.tan.androidtest.anim.property;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.tan.androidtest.util.SizeUtils;

/**
 * Created by Administrator on 2018/4/17.
 */

public class LoadView extends View {

    private int mWidth;
    private int mHeight;

    public LoadView(Context context) {
        this(context, null);
    }

    public LoadView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public LoadView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        if (widthMode == MeasureSpec.EXACTLY) {//当画布的大小为明确值MATCH_CONTENT
            mWidth = widthSize;
        } else {
            mWidth = (int) SizeUtils.dpToPixel(200);
        }
        if (heightMode == MeasureSpec.EXACTLY) {//
            mHeight = heightSize;
        } else {
            mHeight = (int) SizeUtils.dpToPixel(200);
        }
        setMeasuredDimension(mWidth, mHeight);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        Paint paint = new Paint();
        paint.setAntiAlias(true);//消除锯齿
        paint.setStrokeWidth(1);//设置画笔的宽度
        paint.setStyle(Paint.Style.STROKE);//设置绘制轮廓
        paint.setColor(Color.parseColor("#2EA4F2"));//设置颜色
        //RectF rectF = new RectF(SizeUtils.dp2px(getContext(), 75), SizeUtils.dp2px(getContext(), 75), SizeUtils.dp2px(getContext(), 125), SizeUtils.dp2px(getContext(), 125));
        //canvas.drawRect(rectF, paint);
    }
}

